$(document).ready(function() {
    $('#data-table').dataTable({
        "sAjaxSource": url + "/control/menulist.html",
        "bServerSide": true,
        "bJQueryUI": true,
        "oLanguage": {
            "sSearch": "搜索：",
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "抱歉， 没有找到",
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty": "没有数据",
            "sInfoFiltered": "(从 _TOTAL_ 条数据中检索)",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "sZeroRecords": "没有检索到数据",
        },
        "aaSorting": [[0, 'desc']],
        "aoColumns": [
            {"mDataProp": "id",
                "sWidth": "1%",
                "bSortable": false,
                "mRender": function(data, type, full) {
                    return '<input type="checkbox" id="check" value="' + data + '" />';
                }
            },
            {"mDataProp": "typename",
                "fnRender": function(obj) {
                    var sReturn = obj.aData.typename;
                    return "<a href='"+url+"/control/menuedit/"+obj.aData.id+".html' >"+sReturn+"</a>";
                }
            },
            {"mDataProp": "isnews",
                "sWidth": 100,
                 "fnRender": function(obj) {
                    var sReturn = obj.aData.isnews;
                    if(sReturn)
                        return "新闻";
                    else
                        return "单页文档";
                }
            },
            {"mData": null,
                "bSortable": false,
                "sWidth": 40,
                "fnRender": function(obj) {
                    var sReturn = '<a id="del" rel="' + obj.aData.id + '" href="#" class="tip" data-original-title="删除"><i class="icon-remove"></i></a>';
                    return sReturn;
                }
            }
        ],
        "fnServerData": function(sSource, aoData, fnCallback) {
            $.ajax({
                "dataType": 'json',
                "type": "post",
                "url": sSource,
                "data": aoData,
                "success": function(resp)
                {
                    fnCallback(resp);
                    $("[id=del]").click(function(){
                        var td=$(this).parents("tr");
                        var id=$(this).attr("rel");
                        $.post(url+"/control/menu/del.html",{id:id},function(data){
                            if(data){
                                alert("删除成功!");
                                td.remove();
                            }else
                                alert("删除失败!"); 
                        },"json");
                    });
                }
            });
        }
    });
});

